package com.yidu.drug.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.drug.action.vo.ContractTableVo;
import com.yidu.drug.common.Message;
import com.yidu.drug.model.ContractTableModel;
import com.yidu.drug.service.ContractTableService;

@Controller
@RequestMapping("/contractTableAction")
public class ContractTableAction {
	@Resource
	private ContractTableService contractTableService;
	Message msg = new Message();
	
	/**
	 * 根据ID修改
	 */
	@RequestMapping("update")
	public Message updateById(ContractTableModel ctm){
		System.out.println("进入材料根据ID修改的方法，ID为："+ctm.getConId());
		//修改信息
		int count=contractTableService.updateByPrimaryKeySelective(ctm);
		msg.setNum(count);
		return msg;
	}
	
	/**
	 * 根据订单id查询数据
	 * @param fdPoId
	 * @return
	 */
	@RequestMapping("findById")
	@ResponseBody
	public ContractTableModel findById(String conId) {
		 
		return contractTableService.findById(conId);
		
	}

	
	/**
	 *删除的方法 
	 */
	@RequestMapping("deletes")
	@ResponseBody
	public Message delete(ContractTableVo ctm){
		System.out.println("进入用户删除的方法"+ctm.getConId()+"===================");
		contractTableService.delete(ctm.getConId());
		msg.setMsg("ok");
		return msg;
	}
	
	/**
	 * 查询所有
	 * @return
	 */
	@RequestMapping("findAlls")
	@ResponseBody
	public Map<String, Object> findAlls(){
		List<ContractTableModel> findAlls = contractTableService.findAlls();
		Map<String, Object> map = new HashMap<String, Object>();
		//需要符合layUI格式，code msg count data
		map.put("code", 0);
		map.put("msg", "1");
		map.put("count", findAlls.size());
		System.out.println("111111111111"+findAlls.size());
		map.put("data", findAlls);
		return map;
	}
	
	/**
	 * 增加
	 * @param session
	 * @param foodId
	 * @param commentContent
	 * @return
	 */
	@RequestMapping("add")
	@ResponseBody
	public Message add(HttpSession session, ContractTableVo con) {
		Date date = new Date();
		con.setConTime(date);
		con.setConComment("甲方供货给乙方，乙方付款");
		con.setIsva("有效");
		con.setConId(UUID.randomUUID().toString().replaceAll("-", ""));
		int add = contractTableService.add(con);
		
		if(add>0){
			msg.setMsg("成功");
			msg.setNum(1);
			return msg;
		}else{
			msg.setMsg("失败");
			msg.setNum(0);
			return msg;
		}
	}
	
	/**
	 * 王志伟的查询所有的方法
	 * @return 返回 合同的集合
	 */
	@RequestMapping("findAll")
	@ResponseBody
	public List<ContractTableModel> findAll(){
		return contractTableService.findAll();
	}
}